//
// Created by 吴锐 on 2022/3/2.
//

#include <list>
#include "iostream"
#include "string"

using namespace std;

class Person {
public:
    string m_Name;
    int m_Age;
    int m_Height;

    Person(string name, int age, int height){
        this->m_Name = name;
        this->m_Age = age;
        this->m_Height = height;
    }
};

bool comparePerson(Person& p1, Person& p2){
    if(p1.m_Age == p2.m_Age){
        return p1.m_Height > p2.m_Height;
    }else {
        return p1.m_Age < p2.m_Age;
    }
}

void test01(){
    list<Person> l;

    Person p1("牛马一号",35,175);
    Person p2("牛马二号",36,180);
    Person p3("牛马三号",37,154);
    Person p4("牛马四号",33,176);
    Person p5("牛马五号",15,198);
    Person p6("牛马六号",20,134);

    l.push_back(p1);
    l.push_back(p2);
    l.push_back(p3);
    l.push_back(p4);
    l.push_back(p5);
    l.push_back(p6);

    for(list<Person>::iterator it = l.begin() ; it != l.end() ; it++){
        cout << "姓名: " << (*it).m_Name << " 年龄: " << (*it).m_Age << " 身高: " << (*it).m_Height << endl;
    }

    cout << "排序后:" << endl;

    l.sort(comparePerson);

    for(list<Person>::iterator it = l.begin() ; it != l.end() ; it++){
        cout << "姓名: " << (*it).m_Name << " 年龄: " << (*it).m_Age << " 身高: " << (*it).m_Height << endl;
    }
}

int main(){
    test01();
    return 0;
}